package com.cskaoyan.app.service.impl;

import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketBrand;
import com.cskaoyan.app.bean.po.MarketCategory;
import com.cskaoyan.app.bean.po.MarketCategoryExample;
import com.cskaoyan.app.bean.vo.CategoryDataVo;
import com.cskaoyan.app.bean.vo.CategoryL1;
import com.cskaoyan.app.mapper.MarketCategoryMapper;
import com.cskaoyan.app.service.AdminCategoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @Author: 廖平安
 * @CreateTime: 2022-12-29  16:41
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class AdminCategoryServiceImpl implements AdminCategoryService {
    @Autowired
    MarketCategoryMapper categoryMapper;

    @Override
    public CommonData<CategoryDataVo> list() {
//        MarketCategoryExample example = new MarketCategoryExample();
//        example.createCriteria().andDeletedEqualTo(false);
        //List<MarketCategory> market = categoryMapper.selectByExample(example);
        List<CategoryDataVo> list = categoryMapper.queryAllCategory();
        PageInfo<CategoryDataVo> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }

    @Override
    public CommonData<CategoryL1> l1() {
//        MarketCategoryExample example = new MarketCategoryExample();
//        MarketCategoryExample.Criteria criteria = example.createCriteria();
//        criteria.andPidEqualTo(0);
        List<CategoryL1> categoryList = categoryMapper.selectByPid();
        PageInfo<CategoryL1> pageInfo = new PageInfo<>(categoryList);
        return CommonData.data(pageInfo);
    }

    @Override
    public MarketCategory create(MarketCategory marketCategory) {
        int i = categoryMapper.insertSelective(marketCategory);
        Integer id = marketCategory.getId();
        MarketCategory category = categoryMapper.selectByPrimaryKey(id);
        return category;
    }

    @Override
    public void update(MarketCategory category) {
        categoryMapper.updateByPrimaryKey(category);
    }

    @Override
    public void delete(CategoryDataVo categoryDataVo) {
        Integer id = categoryDataVo.getId();
        categoryMapper.update(id);
    }
}

